package at.knorre.swipebeam;

import java.util.List;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;

public class SwipeBeamPreferences extends PreferenceActivity implements
		OnSharedPreferenceChangeListener {

	public static final String SHARED_PREFS_NAME = "swipe_beam_prefs";
	public static final String PREF_COLOR_SCHEME = "pref_colorScheme";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getPreferenceManager().setSharedPreferencesName(SHARED_PREFS_NAME);
		addPreferencesFromResource(R.xml.preferences);
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
		/* get preference */
		Preference preference = findPreference(key);

		/* update summary */
		if (key.equals(PREF_COLOR_SCHEME)) {
			preference.setSummary(((ListPreference) preference).getEntry());
		}
	}

	@Override
	public void onResume() {
		super.onResume();
		getPreferenceManager().getSharedPreferences()
				.registerOnSharedPreferenceChangeListener(this);
	}

	@Override
	public void onPause() {
		getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(
				this);
		super.onPause();
	}

}
